# Makefile for ESP32C3 FreeRTOS project

# Target configuration
TARGET = esp32c3-freertos
ARCH = riscv32

# Toolchain configuration
CC = riscv-none-elf-gcc
LD = riscv-none-elf-ld
OBJCOPY = riscv-none-elf-objcopy
OBJDUMP = riscv-none-elf-objdump

# Compiler flags
CFLAGS = -march=rv32imc -mabi=ilp32 -Os -Wall -Wextra -Werror
CFLAGS += -ffreestanding -nostdlib -nostartfiles
CFLAGS += -Iinclude -Isrc

# Linker flags
LDFLAGS = -T linker.ld

# Source files
SRCS = src/kernel/freertos.c \
       src/drivers/gpio.c \
       src/drivers/uart.c \
       src/drivers/flash.c \
       src/drivers/wifi.c \
       src/network/net_init.c \
       src/app/main.c

# Object files
OBJS = $(SRCS:.c=.o)

# Build targets
all: $(TARGET).bin

$(TARGET).elf: $(OBJS)
	$(LD) $(LDFLAGS) -o $@ $^

$(TARGET).bin: $(TARGET).elf
	$(OBJCOPY) -O binary $< $@

%.o: %.c
	$(CC) $(CFLAGS) -c $< -o $@

clean:
	rm -f $(OBJS) $(TARGET).elf $(TARGET).bin

.PHONY: all clean
